package com.hongxun.design.utils.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.hongxun.design.MyApp;
import com.hongxun.design.NotificationClickReceiver;
import com.hongxun.design.R;

/**
 * Created by zerdoor_pc .
 * author:dc
 * 2016/10/28.
 */
public class NotificationUtil {

    static NotificationUtil instence;

    public static NotificationUtil getinstence() {
        if (instence == null) {
            instence = new NotificationUtil();
        }
        return instence;
    }




    public void inIt(String title, String value, String message){
        Intent notificationIntent = new Intent(MyApp.activity, NotificationClickReceiver.class); //点击通知之后要发送的广播
        notificationIntent.putExtra("message",message);
        notificationIntent.putExtra("title",title);
        notificationIntent.putExtra("value",value);
        PendingIntent contentIntent = PendingIntent.getBroadcast(MyApp.activity, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationManager  mNotificationManager  = (NotificationManager) MyApp.activity.getSystemService(Context.NOTIFICATION_SERVICE);
        //mNotificationManager.cancel(0);
        Notification mNotification = new NotificationCompat.Builder(MyApp.activity)
                .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND)
                // 设置小图标
                .setSmallIcon(R.mipmap.ic_launcher)
                        // 设置标题
                .setContentTitle(title)
                        // 设置内容
                .setContentText(value)

                .setContentIntent(contentIntent)
                .setAutoCancel(true)
                .build();
         mNotificationManager.notify(0, mNotification);

    }


    private String getFrom(String id) {
        if (id.length() == 0) return "";
        return id + ":";
    }
}
